<template>
  <div id="app">
    <template v-if="isLogin">
      <!-- 布局 -->
      <div class="layout">
        <!-- 侧边栏 -->
        <aside class="sidebar">
          <ul>
            <li
              v-for="item in menuList"
              :key="item.path"
              @click="goPage(item.path)"
            >
              {{ item.name }}
            </li>
          </ul>
        </aside>

        <!-- 主体内容 -->
        <div class="main">
          <!-- 顶部导航 -->
          <header class="header">
            <span>欢迎，{{  111 }}</span>
            <button @click="logout">退出登录</button>
          </header>

          <!-- 页面内容 -->
          <main class="content">
            <router-view />
          </main>

          <!-- 底部导航 -->
          <footer class="footer">
            <span>© 2025 我的系统</span>
          </footer>
        </div>
      </div>
    </template>

    <!-- 未登录时只显示登录页面 -->
    <template v-else>
      <router-view />
    </template>
  </div>
</template>

<script setup>
import { computed } from 'vue'
import { useRouter } from 'vue-router'
import { useUserStore } from '@/store/user'

const router = useRouter()
const userStore = useUserStore()

const isLogin = computed(() => userStore.isLogin)
const userInfo = computed(() => userStore.userInfo)
const menuList = computed(() => userStore.menuList)

const goPage = (path) => {
  router.push(path)
}

const logout = () => {
  userStore.logout()
  router.push('/login')
}
</script>

<style scoped>
.layout {
  display: flex;
  height: 100vh;
}
.sidebar {
  width: 200px;
  background: #f5f5f5;
  padding: 10px;
}
.sidebar li {
  list-style: none;
  padding: 8px;
  cursor: pointer;
}
.sidebar li:hover {
  background: #e0e0e0;
}
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
}
.header {
  background: #409eff;
  color: white;
  padding: 10px;
  display: flex;
  justify-content: space-between;
}
.content {
  flex: 1;
  padding: 15px;
  overflow: auto;
}
.footer {
  background: #f1f1f1;
  padding: 8px;
  text-align: center;
}
</style>
